package org.jeecg.modules.api.controller;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/redis/api")
public class RedisController {

    @Autowired
    private RedissonClient redissonClient;

    private static final String REDIS_TEST_KEY = "redis_test_key_";



    @PostMapping("/testRedissonLock")
    public void testRedissonLock(String keyName){

        RLock lock = redissonClient.getLock(REDIS_TEST_KEY + keyName);


        if(lock.tryLock()){

            try {
                Thread.sleep(1000 * 3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }



}
